﻿@using DevExpress.Blazor
@using EasyXaf.LowCode.WorkflowEditors.Models

<div class="@BranchNodeClassName" style="@BranchNodeStyle">
    <div class="top">
        <div class="branch-left-line">
            <div class="h-line"></div>
        </div>
        <div class="branch-center-line">
            <div class="v-line"></div>
        </div>
        <div class="branch-right-line">
            <div class="h-line"></div>
        </div>
    </div>
    <div class="center">
        <div class="content-container">
            <div class="content node-outline" outline-id="outline-@(Branch.Id)">
                @if (WorkflowMode == WorkflowMode.Outline)
                {
                    <div class="node-outline-content" />
                }
                else
                {
                    <DynamicComponent @ref="BranchComponent"
                                      Type="BranchComponentType"
                                      Parameters="BranchComponentParameters" />
                }
            </div>
            @if (CanDelete)
            {
                <NodeAction CssClass="branch-delete-action hidden-action"
                            Tooltip="删除"
                            IconName="Actions_DeleteCircled"
                            Click="Delete" />

                if (CanCopy)
                {
                    <NodeAction CssClass="branch-cut-action hidden-action"
                                Tooltip="剪切"
                                IconName="Actions_Cut"
                                Click="Cut" />
                }
            }
            @if (CanMoveLeft)
            {
                <NodeAction CssClass="branch-move-left-action hidden-action"
                            Tooltip="向左移动"
                            IconName="Actions_Arrow3Left"
                            IconColor="#7F8C8D"
                            Click="MoveLeft" />
            }
            @if (CanMoveRight)
            {
                <NodeAction CssClass="branch-move-right-action hidden-action"
                            Tooltip="向右移动"
                            IconName="Actions_Arrow3Right"
                            IconColor="#7F8C8D"
                            Click="MoveRight" />
            }
        </div>
    </div>
    <div class="bottom">
        <div class="v-line"></div>
        @if (!IsReadOnly)
        {
            <NodeAction Tooltip="添加活动..." IconName="Actions_AddCircled" Click="AddActivityClicked" />
        }
    </div>

    <DxContextMenu @ref="BranchContextMenu">
        <Items>
            @if (Branch.AllowMove)
            {
                <DxContextMenuItem Text="向左移动" CssClass="branch-context-menu-item" Enabled="CanMoveLeft" IconUrl="IImageService/Actions_Arrow4Left" Click="MoveLeft" />
                <DxContextMenuItem Text="向右移动" CssClass="branch-context-menu-item" Enabled="CanMoveRight" IconUrl="IImageService/Actions_Arrow4Right" Click="MoveRight" />
            }
            @if (Branch.AllowScale)
            {
                <DxContextMenuItem Text="大小" CssClass="branch-context-menu-item" Enabled="!IsReadOnly" IconUrl="IImageService/AutoSize" BeginGroup="true">
                    <Items>
                        @for (var i = 1.0; i <= 8; i += (i >= 5 ? 1 : 0.5))
                        {
                            var scale = i;
                            var menuText = $"{scale}倍";
                            var iconUrl = string.Empty;
                            if (Branch.ViewMode == NodeViewMode.Title)
                            {
                                if (Branch.TitleViewScale == scale)
                                {
                                    iconUrl = "IImageService/Actions_Check";
                                }
                            }
                            else
                            {
                                if (Branch.DetailViewScale == scale)
                                {
                                    iconUrl = "IImageService/Actions_Check";
                                }
                            }
                            <DxContextMenuItem Text="@menuText" CssClass="branch-context-menu-item" IconUrl="@iconUrl" Click="()=>SetScale(scale)" />
                        }
                    </Items>
                </DxContextMenuItem>
            }
            @if (AllowAddingComment)
            {
                <DxContextMenuItem Text="添加备注" CssClass="branch-context-menu-item" Enabled="!IsReadOnly" IconUrl="IImageService/Actions_Comment" BeginGroup="true" Click="AddComment" />
            }
            @if (AllowCopy)
            {
                <DxContextMenuItem Text="复制" CssClass="branch-context-menu-item" Enabled="!IsReadOnly" IconUrl="IImageService/Actions_Copy" BeginGroup="true" Click="Copy" />
                if (AllowDelete)
                {
                    <DxContextMenuItem Text="剪切" CssClass="branch-context-menu-item" Enabled="!IsReadOnly&&CanDelete" IconUrl="IImageService/Actions_Cut" Click="Cut" />
                }
            }
            @if (AllowPaste)
            {
                <DxContextMenuItem Text="粘贴" CssClass="branch-context-menu-item" Enabled="CanPaste" IconUrl="IImageService/Action_Paste" Click="Paste" />
            }
            @if (AllowDelete)
            {
                <DxContextMenuItem Text="删除" CssClass="branch-context-menu-item" Enabled="!IsReadOnly&&CanDelete" IconUrl="IImageService/Actions_Delete" BeginGroup="true" Click="Delete" />
            }
            @if (Branch.AllowValidate)
            {
                <DxContextMenuItem Text="验证" CssClass="branch-context-menu-item" Enabled="!IsReadOnly" IconUrl="IImageService/BO_Validation" BeginGroup="true" Click="Validate" />
            }
        </Items>
    </DxContextMenu>
</div>

<style>
    .branch-context-menu-item img {
        width: 16px;
        height: 16px;
    }
</style>